package com.xc.stock.utils;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.BooleanExpression;

public class ConditionBuilder {
	BooleanExpression expression;
	BooleanBuilder booleanBuilder;
	
	public ConditionBuilder and(Predicate and) {
		expression = expression.and(and);
		booleanBuilder.and(and);
		return this;
	}
	
	public ConditionBuilder and(Predicate... and) {
		for (Predicate predicate : and) {
			expression = expression.and(predicate);
		}
		
		booleanBuilder.andAnyOf(and);
		return this;
	}
	
	public ConditionBuilder or(Predicate or) {
		expression = expression.or(or);
		booleanBuilder.or(or);
		return this;
	}
	
	public static ConditionBuilder builder() {
		ConditionBuilder builder = new ConditionBuilder();
		builder.expression = AnyWhereConditionPath.anyWherePredicate();
		builder.booleanBuilder = new BooleanBuilder();
		return builder;
	}
	
	public Predicate predicate() {
		return booleanBuilder.getValue();
	}
	
	public BooleanExpression build() {
		return expression;
	}
}
